package com.acwing.partition9;

import java.io.*;
import java.util.LinkedList;

/**
 * @author `RKC`
 * @date 2021/12/1 15:15
 */
public class AC860染色法判定二分图 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
        int[][] edges = new int[m][2];
        for (int i = 0; i < m; i++) {
            s = reader.readLine().split(" ");
            edges[i][0] = Integer.parseInt(s[0]);
            edges[i][1] = Integer.parseInt(s[1]);
        }
        if (dyeing(n, edges)) writer.write("Yes\n");
        else writer.write("No\n");
        writer.flush();
    }

    private static boolean dyeing(int n, int[][] edges) {
        int m = edges.length, index = 0;
        int[] head = new int[n + 1], element = new int[2 * m], next = new int[2 * m], color = new int[n + 1];
        for (int i = 1; i <= n; i++) head[i] = -1;
        //创建无向图
        for (int[] edge : edges) {
            element[index] = edge[1];
            next[index] = head[edge[0]];
            head[edge[0]] = index++;
            element[index] = edge[0];
            next[index] = head[edge[1]];
            head[edge[1]] = index++;
        }
        for (int i = 1; i <= n; i++) {
            if (color[i] != 0) continue;
//            if (!dfs(head, element, next, color, 1, i)) return false;
            if (!bfs(head, element, next, color, i)) return false;
        }
        return true;
    }

    private static boolean dfs(int[] head, int[] element, int[] next, int[] color, int curColor, int u) {
        color[u] = curColor;
        for (int i = head[u]; i != -1; i = next[i]) {
            int v = element[i];
            //邻结点需要和当前结点的颜色不同，如果相同，返回false
            if (color[v] != 0 && color[u] == color[v]) return false;
            if (color[v] == 0 && !dfs(head, element, next, color, 3 - curColor, v)) return false;
        }
        return true;
    }

    private static boolean bfs(int[] head, int[] element, int[] next, int[] color, int u) {
        LinkedList<int[]> queue = new LinkedList<>();
        queue.addLast(new int[]{u, 1});
        color[u] = 1;
        while (!queue.isEmpty()) {
            int[] tuple = queue.pollFirst();
            u = tuple[0];
            int c = tuple[1];
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (color[v] != 0 && color[v] == c) return false;
                if (color[v] == 0) {
                    color[v] = 3 - c;
                    queue.addLast(new int[]{v, 3 - c});
                }
            }
        }
        return true;
    }
}
